﻿using System;
using System.Collections.Generic;
using System.Web;
using SubSonic;


namespace TCMSystem
{
    public class RoleMenuHelper
    {
        private static Dictionary<int, List<int>> _roleMenus = new Dictionary<int, List<int>>();

        public static void UpdateRoleMenus(int roleId)
        {
            if (_roleMenus.ContainsKey(roleId))
            {
                _roleMenus.Remove(roleId);
            }
        }

        public static List<int> GetRoleMenus(int roleId)
        {
            if (!_roleMenus.ContainsKey(roleId))
            {
                _roleMenus[roleId] = new List<int>();

                TblMstRolemenuCollection roleMenus = new Select().From<TblMstRolemenu>()
                   .Where(TblMstRolemenu.Columns.RoleId).IsEqualTo(roleId)
                   .ExecuteAsCollection<TblMstRolemenuCollection>();

                foreach (TblMstRolemenu roleMenu in roleMenus)
                {
                    _roleMenus[roleId].Add(roleMenu.MenuId);
                }

            }

            return _roleMenus[roleId];
        }


    }
}
